new Vue({

    data:{
        info:{
            company:"",
            phone:"",
            contact_people:"",
            intent_city:"",
            address:"",
            email:"",
            contents:""
        }
    },
    //\u4e00-\u9fa5
    methods:{
        submit:function(event){

            if(!/^[\u4e00-\u9fa5a-zA-Z]{2,30}$/.test(this.info.company)){
                alert('公司名称错误,输入2至30个字符');
                return;
            }


            if(!/^1[34578]\d{9}$/.test(this.info.phone)){
                alert("电话号错误！");
                return;
            }

            if(!/^[\u4e00-\u9fa5a-zA-Z0-9]{2,30}$/.test(this.info.contact_people) ){
                alert('意向人名称错误，请输入3至30个字符');
                return;
            }

            if( !/^[\u4e00-\u9fa5a-zA-Z]{2,20}$/.test(this.info.intent_city) ){
                alert('城市名称错误，请输入2至20个字符');
                return;
            }


            if( !/^[\u4e00-\u9fa5a-zA-Z0-9]{2,20}$/.test(this.info.address) ){
                alert('公司地址名称错误，请输入2至20个字符');
                return;
            }


            if( !/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(this.info.email) ){
                alert('邮箱格式错误');
                return;
            }

            if( !/^.+$/.test(this.info.contents) ){
                alert('内容必填');
                return;
            }


            var formData = JSON.stringify(this.info);
           // this.$http.options.emulateJSON = true;
            this.$http.post( 'api/web-page/feedback?',formData ).then(function (response) {

                return response.json();

            }).then(function(result){
                if( result.code !== 0 ){
                    alert("提交失败");
                    throw new Error("提交失败,code："+result.code);
                }

                alert("提交成功");
                // console.dir(result.create);

            }).catch(function (error) {
                console.error(error);
            });

            this.info.company ="";
            this.info.phone ="";
            this.info.contact_people ="";
            this.info.intent_city ="";
            this.info.address ="";
            this.info.email ="";
            this.info.contents ="";

        }
    }

}).$mount('#join');
